package com.lianbang.pharmacy.http.intercept

import cn.ubest.mvvmcore.utils.SpUtils
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * Created by maoqi on 2020/9/22.
 */
/**
 * 头部添加的参数
 * Created by maoqi on 2018/7/12.
 */
class HeaderIntercept : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val original = chain.request()
        val builder = original.newBuilder()
        val token = SpUtils.getString("token", "")

        //Token
        if (token.isNotEmpty()) {
            builder.header("token", token)
        }
        return chain.proceed(builder.build())
    }
}